package com.gitee.wsl.doc.opml

import com.gitee.wsl.doc.SampleReader
import com.gitee.wsl.doc.opml.ValidityCheck.isTextBlank
import com.gitee.wsl.doc.opml.ValidityCheck.translate
import com.gitee.wsl.doc.opml.bean.Opml
import com.gitee.wsl.doc.xml.EventType
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue


@Throws(OpmlParseException::class)
fun SampleReader.parse(filename: String): Opml {
    val sample: String = read(filename)
    return OpmlParser().parse(sample)
}

class ValidityCheckTest {
    @Test
    fun translateTest() {
        assertEquals("START_DOCUMENT", translate(EventType.START_DOCUMENT))
        assertEquals("START_TAG", translate(EventType.START_TAG))
        assertEquals("TEXT", translate(EventType.TEXT))
        assertEquals("END_TAG", translate(EventType.END_TAG))
        assertEquals("END_DOCUMENT", translate(EventType.END_DOCUMENT))
        //assertEquals("123", translate(123))
    }

//    @Test
//    fun requirePosition() {
//        val parser: XmlPullParser = Mockito.mock(XmlPullParser::class.java)
//        try {
//            Mockito.`when`(parser.eventType).thenReturn(XmlPullParser.END_TAG)
//            requirePosition(parser, XmlPullParser.START_TAG)
//        } catch (e: OpmlParseException) {
//            assertEquals("required position START_TAG but found position END_TAG", e.message)
//        } catch (e: XmlPullParserException) {
//            throw RuntimeException(e)
//        }
//    }

//    @Test(expected = OpmlParseException::class)
//    @Throws(OpmlParseException::class, XmlPullParserException::class)
//    fun wrapXmlPullParserException() {
//        val parser: XmlPullParser = Mockito.mock(XmlPullParser::class.java)
//        Mockito.`when`(parser.eventType).thenThrow(XmlPullParserException::class.java)
//        requirePosition(parser, XmlPullParser.START_DOCUMENT)
//    }

    @get:Test
    val isTextBlank: Unit
        get() {
           assertTrue(isTextBlank(null as String?))
           assertTrue(isTextBlank("   	"))
           assertTrue(isTextBlank(""))
        }
}
